package com.situ.util.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.util.service.CstCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.util.service.CstLostService;
import com.situ.util.entity.CstLost;
import com.situ.util.*;

import java.util.List;
import java.util.Map;

/**
 * CstLost的路由接口服务
 * 
 * @author 
 *
 */
@RestController
public class CstLostController {

	/** CstLostService服务 */
	@Autowired
	private CstLostService cstLostService;
	@Autowired
	private CstCustomerService cstCustomerService;
	//带条件的分页查询流失表
	@RequestMapping("/queryLostByUid")
	public ResponseData queryLostByUid(CstLost c,
									@RequestParam(defaultValue ="1",required = false) int startPage ,
									@RequestParam(defaultValue = "5",required = false) int PageSize){
		try {
			PageHelper.startPage(startPage, PageSize);
			List<CstLost> clist=cstLostService.queryLostbyUid(c);//查询的上面和下面加一行代码包起来
			PageInfo pageInfo = new PageInfo<CstLost>(clist,5);
			return ResponseData.ok().putDataValue("lostlist",clist).putDataValue("pageInfo",pageInfo).putDataValue("Pagesize", PageSize);
		}catch (Exception e){
			e.printStackTrace();
			return ResponseData.serverInternalError();
		}
	}
	//根据id查对应流失内容
	@GetMapping("/queryLostByLid")
	public ResponseData querylostbylid(Integer id) {
		CstLost c=cstLostService.querylostbyLid(id);
		return ResponseData.ok().putDataValue("lost",c);
	}
	//暂缓流失
	@GetMapping("/canback")
	public ResponseData canback(CstLost c) {
		cstLostService.canback(c);
		return ResponseData.ok();
	}
	//确认流失
	@GetMapping("/cannoback")
	public ResponseData cannoback(CstLost c) {
		cstLostService.cannoback(c);//改流失表
		cstCustomerService.delcustomer(c.getLst_cust_no());//改客户表
		return ResponseData.ok();
	}

}
